package net.sk.china.city.mapper;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import net.sk.china.city.domain.User;
import net.sk.china.city.domain.dto.analyse.GridVolunteerAnalysis;
import net.sk.china.city.domain.dto.analyse.GridVolunteerItem;
import net.sk.china.city.domain.dto.analyse.VolunteerCountRankDTO;
import net.sk.china.city.domain.dto.user.UserSearchDTO;
import net.sk.china.city.domain.dto.user.UserUpdateDTO;
import net.sk.china.city.domain.dto.user.VolunteerPopulationDTO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 前台用户Mapper接口
 * 
 * @author yangguanjin
 * @date 2024-04-07
 */
@Mapper
public interface UserMapper extends BaseMapper<User>
{
    /**
     * 查询前台用户
     * 
     * @param pkId 前台用户主键
     * @return 前台用户
     */
    public User selectUserByPkId(Long pkId);

    /**
     * 查询前台用户列表
     * 
     * @param userSearchDTO 查询条件
     * @return 前台用户集合
     */
    public Page<User> selectUserList(UserSearchDTO userSearchDTO);

    public Page<User> selectUserList2(UserSearchDTO userSearchDTO);

    /**
     * 新增前台用户
     * 
     * @param userUpdateDTO 前台用户
     * @return 结果
     */
    public int insertUser(UserUpdateDTO userUpdateDTO);

    /**
     * 修改前台用户
     * 
     * @param userUpdateDTO 前台用户
     * @return 结果
     */
    public int updateUser(UserUpdateDTO userUpdateDTO);

    /**
     * 修改积分
     * @param userUpdateDTO
     * @return
     */
    public int updatePoint(UserUpdateDTO userUpdateDTO);

    /**
     * 通过审核后，将用户更新为志愿者
     * */
    public int updateUserToVolunteer(User user);

    /**
     * 删除前台用户
     * 
     * @param pkId 前台用户主键
     * @return 结果
     */
    public int deleteUserByPkId(Long pkId);

    /**
     * 批量删除前台用户
     * 
     * @param pkIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteUserByPkIds(Long[] pkIds);

    int insertUserBatch(@Param("userList") List<User> userList);

    @Select("select pk_id, phone, point from ar_user where phone = #{phone}")
    User getUserByPhone(String phone);

    Long countVolunteer(String platformId);

    BigDecimal volunteerAvgWorkHour(String platformId);

    int addPoint(@Param("userId") Long userId,
                 @Param("point") Long point,
                 @Param("workHour") Long workHour);

    @Select("select pk_id, phone, point from ar_user where account = #{phone} and is_delete = 0")
    Optional<User> selectUserByAccount(String phone);

    BigDecimal sumWorkHour(String platformId);
    /**
     * 志愿者人员分布
     * @return
     */
    List<VolunteerPopulationDTO> volunteerPopulation(String platformId);

    List<VolunteerCountRankDTO> analyseSiteVolunteerTop10(@Param("startDate") LocalDate startDate,
                                                          @Param("endDate") LocalDate endDate);

    GridVolunteerAnalysis analyseGridVolunteerData(Long gridId);

    Long analyseGridActivityCount(Long gridId);

    Page<GridVolunteerItem> getGridVolunteerPage();

    User selectTeamLeader(@Param("managedTeamId") Long managedTeamId);

    long previousMonthTeamMemberCount();

    Page<GridVolunteerItem> selectServiceSiteVolunteer(Long siteId);

    Page<GridVolunteerItem> selectUserPageByRegionIdList(String fullRegionId);

    List<User> selectUserListByPkIdList(@Param("pkIds") Long[] pkIds);
}
